
package com.qipay.mapper;

import com.qipay.baas.model.Order;
import com.qipay.core.entity.ValueObject;
import com.qipay.order.vo.*;
import com.qipay.sp.dto.SpUserOrderListDto;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper extends com.qipay.baas.mapper.OrderMapper {
    @Select({"select *",
            "from `order`",
            "where state = 6 and sp_id = #{spid,jdbcType=BIGINT} and  create_time>= #{startTime,jdbcType=VARCHAR} order by id desc"})
    List<Order> selectBySpidTime(@Param("spid") Long spid,@Param("startTime") String startTime);

    @Select({
            "select ",
            "IFNULL(sum(advance_amount),0) advanceAmount,IFNULL(sum(amount),0) amount",
            "from `order` ",
            "where state =3 and description = #{description,jdbcType=VARCHAR}"
    })
    Order selectSumSpUserFee(String description);

    @Select({"SELECT IFNULL(SUM(actual_amount),0)total from `order` where cp_id = #{cpId,jdbcType=BIGINT} and state=3"})
    Long sumOrderByCp(@Param("cpId") Long cpId);

    @Select({"SELECT IFNULL(SUM(actual_amount),0)total from `order` where cp_id = #{cpId,jdbcType=BIGINT} and state=4"})
    Long sumDisOrderByCp(@Param("cpId") Long cpId);


    @Select({"select *",
            "from `order`",
            "where state = 6 and  body = #{remark,jdbcType=VARCHAR} and DATE_SUB(CURDATE(), INTERVAL 1 DAY) <=create_time order by create_time desc"})
    List<Order> getByRemark(@Param("remark") String remark);

    @Select({"select *",
            "from `order`",
            "where state = 6 and  body like CONCAT('%', #{body, jdbcType=VARCHAR}, '%') and DATE_SUB(CURDATE(), INTERVAL 1 DAY) <=create_time order by create_time desc"})
    List<Order> getByBodyLike(@Param("body") String body);

    @Select({"select *",
            "from `order`",
            "where body = #{remark,jdbcType=VARCHAR}"})
    Order getSureOrder(@Param("remark") String remark);

    @Select({"SELECT IFNULL(SUM(o.amount),0)total from `order` o LEFT JOIN sp ON o.sp_id=sp.id where sp.sp_user_name = #{spUserName,jdbcType=VARCHAR} " +
            "and o.state=3 and o.create_time>= #{form,jdbcType=VARCHAR} and o.create_time<= #{to,jdbcType=VARCHAR}"})

    Long sumOrderBySpUser(@Param("spUserName") String spUserName,
                          @Param("form") String form,
                          @Param("to") String to);


    //*******************以下更改商户以及提现模块的之前的代码
    @SelectProvider(type = OrderSqlProvider.class, method = "sumOrder")
    @Results({
            @Result(column = "total", property = "total"),
            @Result(column = "amountCount", property = "amountCount"),
            @Result(column = "advanceAmount", property = "advanceAmount"),
            @Result(column = "feeCount", property = "feeCount")
    })
    OrderSumVo sumOrder(String querysql);

    @SelectProvider(type = OrderSqlProvider.class, method = "countBy")
    long countBy(String querysql);

    //统计查询总金额
    @SelectProvider(type = OrderSqlProvider.class, method = "amountCount")
    long amountCount(String querysql);

    //统计查询总金额
    @SelectProvider(type = OrderSqlProvider.class, method = "feeCount")
    long feeCount(String querysql);

    //根据商户号查询
    @SelectProvider(type = OrderSqlProvider.class, method = "listCp0Tj")
    List<CpTjVo> listCp0Tj(String from, String to, Long cpid);

    //根据bank查询
    @SelectProvider(type = OrderSqlProvider.class, method = "listSp0Tj")
    List<SpTjVo> listSp0Tj(String from, String to, Long spid);

    @SelectProvider(type = OrderSqlProvider.class, method = "listChannel0Tj")
    List<ChannelTjVo> listChannel0Tj(String from, String to, int channelid);

    @SelectProvider(type = OrderSqlProvider.class, method = "listChannelSp0Tj")
    List<ChannelSpTjVo> listChannelSp0Tj(String from, String to, String spid, int channelid);

    @SelectProvider(type = OrderSqlProvider.class, method = "listCp_Sp0Tj")
    List<Cp_SpTjVo> listCp_Sp0Tj(String from, String to, String cpid, int channelid);

    @SelectProvider(type = OrderSqlProvider.class, method = "listBy")
    @Results({
            @Result(column = "cpName", property = "cpName"),
            @Result(column = "agentId", property = "agentId"),
            @Result(column = "agentName", property = "agentName"),

            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "cp_id", property = "cpId", jdbcType = JdbcType.BIGINT),
            @Result(column = "body", property = "body", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee", property = "fee", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee_recharge", property = "feeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "actual_amount", property = "actualAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "disable_amount", property = "disableAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_id", property = "agentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "agent_fee", property = "agentFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_fee_recharge", property = "agentFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "trade_no", property = "tradeNo", jdbcType = JdbcType.CHAR),
            @Result(column = "out_trade_no", property = "outTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_trade_no", property = "spTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "settle_status", property = "settleStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_url", property = "notifyUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attach", property = "attach", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_id", property = "spId", jdbcType = JdbcType.BIGINT),
            @Result(column = "channel_type", property = "channelType", jdbcType = JdbcType.TINYINT),
            @Result(column = "sp_fee_recharge", property = "spFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sp_fee", property = "spFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "sp_mch_id", property = "spMchId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "finish_time", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
    })
    List<OrderListItem> listBy(String querysql, Object offset, Object rowss);


    @SelectProvider(type = OrderSqlProvider.class, method = "listBy0")
    @Results({
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR)
    })
    List<OrderListItem> listBy0(String querysql,String orderBy);

    @Select({
            "select *",
            "from `order`",
            "where cp_id = #{cp_id,jdbcType=BIGINT}",
            " and out_trade_no = #{out_trade_no,jdbcType=VARCHAR} "
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "cp_id", property = "cpId", jdbcType = JdbcType.BIGINT),
            @Result(column = "body", property = "body", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee", property = "fee", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee_recharge", property = "feeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "actual_amount", property = "actualAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "disable_amount", property = "disableAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_id", property = "agentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "agent_fee", property = "agentFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_fee_recharge", property = "agentFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "trade_no", property = "tradeNo", jdbcType = JdbcType.CHAR),
            @Result(column = "out_trade_no", property = "outTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_trade_no", property = "spTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "settle_status", property = "settleStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_url", property = "notifyUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attach", property = "attach", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_id", property = "spId", jdbcType = JdbcType.BIGINT),
            @Result(column = "channel_type", property = "channelType", jdbcType = JdbcType.TINYINT),
            @Result(column = "sp_fee_recharge", property = "spFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sp_fee", property = "spFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "sp_mch_id", property = "spMchId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "finish_time", property = "finishTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Order getByCpidAndOutTradeNo(@Param("cp_id") Long cpid, @Param("out_trade_no") String outTradeNo);

    @SelectProvider(type = OrderSqlProvider.class, method = "statementBy")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "cp_id", property = "cpId", jdbcType = JdbcType.BIGINT),
            @Result(column = "body", property = "body", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee", property = "fee", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee_recharge", property = "feeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "actual_amount", property = "actualAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "disable_amount", property = "disableAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_id", property = "agentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "agent_fee", property = "agentFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_fee_recharge", property = "agentFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "trade_no", property = "tradeNo", jdbcType = JdbcType.CHAR),
            @Result(column = "out_trade_no", property = "outTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_trade_no", property = "spTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "settle_status", property = "settleStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_url", property = "notifyUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attach", property = "attach", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_id", property = "spId", jdbcType = JdbcType.BIGINT),
            @Result(column = "channel_type", property = "channelType", jdbcType = JdbcType.TINYINT),
            @Result(column = "sp_fee_recharge", property = "spFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sp_fee", property = "spFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "sp_mch_id", property = "spMchId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "finish_time", property = "finishTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<Order> statementBy(Long cpId, String from, String to, Integer channel);


    @SelectProvider(type = OrderSqlProvider.class, method = "statementAllBy")
    @Results({
            @Result(column = "cpName", property = "cpName"),
            @Result(column = "agentId", property = "agentId"),
            @Result(column = "agentName", property = "agentName"),
            @Result(column = "contacts", property = "contacts"),

            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "cp_id", property = "cpId", jdbcType = JdbcType.BIGINT),
            @Result(column = "body", property = "body", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee", property = "fee", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee_recharge", property = "feeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "actual_amount", property = "actualAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "disable_amount", property = "disableAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_id", property = "agentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "agent_fee", property = "agentFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_fee_recharge", property = "agentFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "trade_no", property = "tradeNo", jdbcType = JdbcType.CHAR),
            @Result(column = "out_trade_no", property = "outTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_trade_no", property = "spTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "settle_status", property = "settleStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_url", property = "notifyUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attach", property = "attach", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_id", property = "spId", jdbcType = JdbcType.BIGINT),
            @Result(column = "channel_type", property = "channelType", jdbcType = JdbcType.TINYINT),
            @Result(column = "sp_fee_recharge", property = "spFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sp_fee", property = "spFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "sp_mch_id", property = "spMchId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "finish_time", property = "finishTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<OrderStatementVo> statementAllBy(String from, String to, Long cpId, String cpName, Long agentId, String contract, Integer channel);

    @SelectProvider(type = OrderSqlProvider.class, method = "statementSpBy")
    @Results({
            @Result(column = "spName", property = "spName"),
            @Result(column = "service", property = "service"),
            @Result(column = "bank", property = "bank"),

            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "cp_id", property = "cpId", jdbcType = JdbcType.BIGINT),
            @Result(column = "body", property = "body", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee", property = "fee", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee_recharge", property = "feeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "actual_amount", property = "actualAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "disable_amount", property = "disableAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_id", property = "agentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "agent_fee", property = "agentFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_fee_recharge", property = "agentFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "trade_no", property = "tradeNo", jdbcType = JdbcType.CHAR),
            @Result(column = "out_trade_no", property = "outTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_trade_no", property = "spTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "settle_status", property = "settleStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_url", property = "notifyUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attach", property = "attach", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_id", property = "spId", jdbcType = JdbcType.BIGINT),
            @Result(column = "channel_type", property = "channelType", jdbcType = JdbcType.TINYINT),
            @Result(column = "sp_fee_recharge", property = "spFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sp_fee", property = "spFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "sp_mch_id", property = "spMchId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "finish_time", property = "finishTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<OrderSpStatementVo> statementSpBy(String from, String to, Long spId, String spName, String service, Integer channel);


    @SelectProvider(type = OrderSqlProvider.class, method = "selectSpUserOrders")
    @Results({
            @Result(column = "cpName", property = "cpName"),
            @Result(column = "agentId", property = "agentId"),
            @Result(column = "agentName", property = "agentName"),

            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "cp_id", property = "cpId", jdbcType = JdbcType.BIGINT),
            @Result(column = "body", property = "body", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee", property = "fee", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee_recharge", property = "feeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "actual_amount", property = "actualAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "disable_amount", property = "disableAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_id", property = "agentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "agent_fee", property = "agentFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_fee_recharge", property = "agentFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "trade_no", property = "tradeNo", jdbcType = JdbcType.CHAR),
            @Result(column = "out_trade_no", property = "outTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_trade_no", property = "spTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "settle_status", property = "settleStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_url", property = "notifyUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attach", property = "attach", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_id", property = "spId", jdbcType = JdbcType.BIGINT),
            @Result(column = "channel_type", property = "channelType", jdbcType = JdbcType.TINYINT),
            @Result(column = "sp_fee_recharge", property = "spFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sp_fee", property = "spFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "sp_mch_id", property = "spMchId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "finish_time", property = "finishTime", jdbcType = JdbcType.TIMESTAMP),
    })
    List<ValueObject> selectSpUserOrders(Integer spId, String startTime, String endTime);

    @SelectProvider(type = OrderSqlProvider.class, method = "selectSpUserOrdersTotal")
    SpUserOrderListDto selectSpUserOrdersTotal(Integer spId, String startTime, String endTime);

    @Select({
            "select *",
            "from `order`",
            "where state = #{state,jdbcType=TINYINT} limit 1"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "cp_id", property = "cpId", jdbcType = JdbcType.BIGINT),
            @Result(column = "body", property = "body", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee", property = "fee", jdbcType = JdbcType.INTEGER),
            @Result(column = "fee_recharge", property = "feeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "actual_amount", property = "actualAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "advance_amount", property = "advanceAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "disable_amount", property = "disableAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_id", property = "agentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "agent_fee", property = "agentFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "agent_fee_recharge", property = "agentFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "trade_no", property = "tradeNo", jdbcType = JdbcType.CHAR),
            @Result(column = "out_trade_no", property = "outTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_trade_no", property = "spTradeNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "settle_status", property = "settleStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_url", property = "notifyUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attach", property = "attach", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sp_id", property = "spId", jdbcType = JdbcType.BIGINT),
            @Result(column = "channel_type", property = "channelType", jdbcType = JdbcType.TINYINT),
            @Result(column = "sp_fee_recharge", property = "spFeeRecharge", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sp_fee", property = "spFee", jdbcType = JdbcType.INTEGER),
            @Result(column = "sp_mch_id", property = "spMchId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "finish_time", property = "finishTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Order byState(@Param("state") Byte state);

    @Insert("insert into tb_order(order_id,good_url,good_num,amount,type,create_date) " +
            "values(#{id},#{goods_url},#{goods_count},#{amount},'0',sysdate())")
    int insertTbOrder(TbVO tbVO);

    @Update("update tb_order set tb_id = #{tbId},qrcode = #{qrCode}, type = '1' where order_id = #{id}")
    void updateTbOrder(@Param("id") String id, @Param("tbId") String tbId, @Param("qrCode") String qrCode);

    @Select("select order_id ,qrcode, tb_id from tb_order where amount = #{amount} and type = '1' limit 1")
    Map<String, String> selectTbQrCode(@Param("amount") String amount);

    @Update("update tb_order set type = '2' where order_id = #{orderId}")
    void updateTbType(@Param("orderId") String orderId);

    @Update("update tb_order set type = '3' where tb_id = #{taId}")
    void updateTbTypeByTbId(@Param("taId") String tbId);

    @Select("select * from `order` where sp_id in (select id from sp where factory_class_name = 'com.qipay.sp.excutor.zhuanzhuan.ZzFactory') and state = 6")
    List<Order> searchZzOrder();

    @Select("select * from `order` where state = 3 and finish_time >= NOW()-INTERVAL 125 MINUTE and finish_time < NOW()-INTERVAL 120 MINUTE order by finish_time")
    List<Order> searchPddSureOrder();
}